﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcps.Web
{
    public partial class UpdatePass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] == null)
                {
                    //Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "Default.aspx");
                    Maticsoft.Common.MessageBox.ResponseScript(this, "top.location.href='Default.aspx'");
                }
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            string oldpass = this.txt_oldpass.Text;

            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["userpwd"].ToString() == oldpass)
                    {
                        lcps.BLL.userinfo um = new BLL.userinfo();

                        lcps.Model.userinfo user = um.DataTableToList(ds.Tables[0])[0];

                        user.userpwd = this.txt_newpass.Text;

                        if (um.Update(user))
                        {
                            Maticsoft.Common.MessageBox.Show(this,"修改密码成功！");
                        }
                    }
                    else
                    {
                        Maticsoft.Common.MessageBox.Show(this, "旧密码不正确！");
                    }
                }

            }
            else
            {
                //Maticsoft.Common.MessageBox.ShowAndRedirect(this, "由于长时间未登陆，登陆已过期,请重新登陆！", "Default.aspx");
                Maticsoft.Common.MessageBox.ResponseScript(this, "top.location.href='Default.aspx'");
            }
        }
    }
}